<template>
    <div class="root">
        <div class="files">
            <div class="title">{{ $t('langObj.fileInfo') }}</div>
            <div class="files-list"
                v-for="(file, index) in files"
                :class="['file', { active: activeIndex === index }]"
                :key="file.name"
                @click="handleClickFile(index)">
                {{ file.name }}
            </div>
        </div>
        <div class="info">
            <div class="title">{{ $t('langObj.dataDesc') }}</div>
            <div>
                <vue-markdown :source="files.length > 0 ? files[activeIndex].sampleContent : '' "></vue-markdown>
            </div>
        </div>
    </div>
</template>

<script>
import { mapActions } from 'vuex';
import VueMarkdown from 'vue-markdown';
export default {
    components:{
        VueMarkdown
    },
    data() {
        return {
            files:[],
            activeIndex: 0
        }
    },
    methods: {
        ...mapActions(['XgetDataFile']),
        handleClickFile(index) {
            this.activeIndex = index;
        }
    },
    created() {
        this.XgetDataFile(this.$router.currentRoute.params.id).then(res => {
            this.files = res.data
        })
    },
}
</script>

<style lang="scss" scoped>
    .root {
        display: flex;
    }
    .files {
        width: 200px;
        overflow-y: auto;
        flex-shrink: 0;
    }
    .file-list  > div {
        font-size: 13px;
    }

    .file-list > div + div {
        margin-top: 5px;
    }

    .file {
        cursor: pointer;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;

        &:hover {
            color: #2d8cf0;
        }
    }
    .active {
        font-size: 14px;
        color: #2d8cf0;
        font-weight: 500;
    }
    .info {
        margin-left: 20px;
        flex: 1;
    }

    .title {
        color: #17233d;
        font-size: 18px;
        font-weight: 500;
        margin-bottom: 20px;
    }
</style>
